﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataTransferBetweenViews.Model;
using System.Collections.ObjectModel;

namespace DataTransferBetweenViews.ViewModel
{
    public class SenderViewModel
    {
        private IModel model;
        private IList<string> persons;
        private string selectedPerson;

        /// <summary>
        /// Initializes a new instance of the <see cref="SenderViewModel"/> class.
        /// </summary>
        /// <param name="model">The model.</param>
        public SenderViewModel(IModel model)
        {
            this.model = model;
        }

        /// <summary>
        /// Gets the persons.
        /// </summary>
        /// <value>The persons.</value>
        public IList<string> Persons
        {
            get
            {
                if (this.persons == null)
                {
                    this.persons = this.model.GetSubscribedPersons();
                }

                return this.persons;
            }
        }

        /// <summary>
        /// Gets or sets the selected person.
        /// </summary>
        /// <value>The selected person.</value>
        public string SelectedPerson
        {
            get
            {
                return this.selectedPerson;
            }

            set
            {
                this.selectedPerson = value;
                this.model.SelectedPerson = this.selectedPerson;
            }
        }
    }
}
